import {
	baseUrl
} from '@/uits/baseUrl.js'

// 刷新token - 使用uni.request避免循环依赖
export function refreshTokens(data) {
	return new Promise((resolve, reject) => {
		console.log('refreshTokens: 发送刷新token请求', data);
		
		uni.request({
			url: baseUrl + '/api/v1/wechat/refreshToken',
			method: 'POST',
			data: data,
			header: {
				'Content-Type': 'application/json',
				'Authorization': 'Bearer ' + uni.getStorageSync('refreshToken') || ''
			},
			success: (res) => {
				console.log('refreshTokens: 刷新token请求成功', res);
				if (res.statusCode === 200) {
					resolve(res.data);
				} else {
					console.error('refreshTokens: 请求失败，状态码:', res.statusCode);
					reject(new Error(`HTTP ${res.statusCode}`));
				}
			},
			fail: (error) => {
				console.error('refreshTokens: 网络请求失败', error);
				reject(error);
			}
		});
	});
}